package com.huayun.dcsp.service2.dao;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import com.huayun.dcsp.service2.model.Student;


@Repository("studentDao") 
public class StudentDao {

	@Resource(name = "sqlSessionTemplate")
	public SqlSessionTemplate sqlSession;   
	  
	public void setSqlSession(SqlSessionTemplate sqlSession) {   
		 this.sqlSession = sqlSession;   
	} 
	
	public List<Student> getAllStudent() {   
		 return sqlSession.selectList("Student.selectAllStudent");   
	}
	
	public Student getStudentById(String id) {   
		 return (Student)sqlSession.selectOne("Student.selectStudentById", id);   
	}   
	
	public List<Map<String, Object>> queryStudents(String condition) {
		Map<String, Object> map = new HashMap<String, Object>(); 
        map.put("table","STUDENT");  
        map.put("cols", "ID,NAME");
        map.put("condition", condition);

		return sqlSession.selectList("Student.dynamicQuery", map);
	}
}
